<template>
    <div>
        <div class="tableHeader">
            <div class="tableHeaderTitle">通知列表</div>
            <div class="tableHeaderMenu">
                <el-button-group>
                    <el-button icon="el-icon-refresh" @click="refreshData" size="mini"></el-button>
                </el-button-group>
            </div>
        </div>

        <el-table ref="multipleTable" :data="noticeData" tooltip-effect="dark" style="width: 100%">
            <el-table-column label="序号" type="index" width="80"></el-table-column>
            <el-table-column prop="cn_title" label="通知标题"></el-table-column>
            <el-table-column label="创建时间">
                <template slot-scope="scope">
                    {{$common.dateFormat("YYYY-MM-dd hh:mm",scope.row.cn_create_time)}}
                </template>
            </el-table-column>
            <el-table-column label="通知类型">
                <template slot-scope="scope">
                    <span v-if="scope.row.cn_type == 1" >个人</span>
                    <span v-else>系统</span>
                </template>
            </el-table-column>
            <el-table-column label="是否发送">
                <template slot-scope="scope">
                    <span v-if="scope.row.cn_is_send == 1" >是</span>
                    <span v-else>否</span>
                </template>
            </el-table-column>
            <el-table-column label="操作" fixed="right" width="260">
                <template slot-scope="scope">
                    <el-button size="mini" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
                    <el-button size="mini" type="danger" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
                </template>
            </el-table-column>
        </el-table>

        <!--分页-->
        <el-col :span="24">
            <el-pagination
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page="pagination.currentPage"
                    :page-sizes="[20,50,100,200]"
                    :page-size="pagination.pageSize"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="pagination.dataLength"
            ></el-pagination>
        </el-col>
    </div>
</template>

<script>
    import {mapState, mapMutations} from 'vuex'

    export default {
        //数据源
        data() {
            return {}
        },
        //初始化函数
        mounted() {
            this.initData();
        },
        //计算属性
        computed: {
            ...mapState({
                noticeData: state => state.InformListModule.noticeData,
                pagination: state => state.InformListModule.pagination
            })
        },
        //组件方法
        methods: {
            refreshData() {
                this.pagination.skip = 0;
                this.initData();
            },
            handleEdit(index, item) {
                this.$router.push({
                    path: "/editInform",
                    query: {
                        cn_id: item.cn_id
                    }
                });
            },
            handleDelete(index,item){

                var params = {
                    delete_where  : "cn_id",
                    cn_id        : item.cn_id,
                    cn_is_delete : 1
                };

                this.$myPop.confirmBox("确认操作","确定要删除该通知吗？",()=>{
                    this.$myLoading.startLoading()
                    this.$http.postHttp(
                        this.$API.cmsNoticeDelete,
                        params,
                        rs => {
                            this.$myLoading.endLoading()
                            this.$myPop.SuccessMessage()
                            this.initData()
                        }
                    )
                })
            },
            initData() {

                this.$myLoading.startLoading()
                this.$http.getHttp(
                    this.$API.cmsnoticeSearch + "/skip/" + this.pagination.skip + "/limit/" + this.pagination.pageSize + "/cn_is_delete/0/count/1",
                    rs => {
                        console.log(rs);
                        this.$store.commit('InformListModule/updateNoticeData', rs.data)
                        this.$store.commit('InformListModule/updatePaginationDataLength', parseInt(rs.count))
                        this.$myLoading.endLoading()
                    }
                )

            },
            handleSizeChange(page){
                this.pagination.pageSize = page;
                this.initData();
            },
            handleCurrentChange(page){
                this.pagination.skip        = (page-1) * this.pagination.pageSize;
                this.pagination.currentPage = page;
                this.initData();

            }
        }
    }
</script>

<style lang="stylus" scoped>
    @import '~PUBLIC_CSS';
</style>